from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-25 14:02:32.370668
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 25, Dec, 2022
Time: 14:02:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3033
Nobs: 881.000 HQIC: -51.6050
Log likelihood: 11653.5 FPE: 3.21472e-23
AIC: -51.7917 Det(Omega_mle): 2.90421e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297707 0.049575 6.005 0.000
L1.Burgenland 0.105827 0.033925 3.119 0.002
L1.Kärnten -0.106796 0.018226 -5.859 0.000
L1.Niederösterreich 0.212502 0.071148 2.987 0.003
L1.Oberösterreich 0.084390 0.067332 1.253 0.210
L1.Salzburg 0.250557 0.036020 6.956 0.000
L1.Steiermark 0.030587 0.047317 0.646 0.518
L1.Tirol 0.127144 0.038503 3.302 0.001
L1.Vorarlberg -0.062052 0.033120 -1.874 0.061
L1.Wien 0.064447 0.060062 1.073 0.283
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063571 0.101873 0.624 0.533
L1.Burgenland -0.009437 0.069714 -0.135 0.892
L1.Kärnten 0.049276 0.037454 1.316 0.188
L1.Niederösterreich -0.172110 0.146205 -1.177 0.239
L1.Oberösterreich 0.361291 0.138363 2.611 0.009
L1.Salzburg 0.285868 0.074020 3.862 0.000
L1.Steiermark 0.109070 0.097233 1.122 0.262
L1.Tirol 0.318923 0.079122 4.031 0.000
L1.Vorarlberg 0.024662 0.068060 0.362 0.717
L1.Wien -0.025146 0.123423 -0.204 0.839
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200393 0.025718 7.792 0.000
L1.Burgenland 0.090437 0.017599 5.139 0.000
L1.Kärnten -0.009110 0.009455 -0.964 0.335
L1.Niederösterreich 0.267373 0.036909 7.244 0.000
L1.Oberösterreich 0.111269 0.034929 3.186 0.001
L1.Salzburg 0.053645 0.018686 2.871 0.004
L1.Steiermark 0.015908 0.024546 0.648 0.517
L1.Tirol 0.102457 0.019974 5.130 0.000
L1.Vorarlberg 0.056674 0.017182 3.298 0.001
L1.Wien 0.111992 0.031158 3.594 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104582 0.026375 3.965 0.000
L1.Burgenland 0.047939 0.018049 2.656 0.008
L1.Kärnten -0.016993 0.009697 -1.752 0.080
L1.Niederösterreich 0.197865 0.037852 5.227 0.000
L1.Oberösterreich 0.277194 0.035822 7.738 0.000
L1.Salzburg 0.117997 0.019164 6.157 0.000
L1.Steiermark 0.100469 0.025174 3.991 0.000
L1.Tirol 0.126984 0.020485 6.199 0.000
L1.Vorarlberg 0.069865 0.017621 3.965 0.000
L1.Wien -0.026709 0.031954 -0.836 0.403
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131767 0.047590 2.769 0.006
L1.Burgenland -0.053914 0.032567 -1.655 0.098
L1.Kärnten -0.037018 0.017497 -2.116 0.034
L1.Niederösterreich 0.166494 0.068299 2.438 0.015
L1.Oberösterreich 0.132640 0.064636 2.052 0.040
L1.Salzburg 0.290810 0.034578 8.410 0.000
L1.Steiermark 0.034536 0.045422 0.760 0.447
L1.Tirol 0.161788 0.036962 4.377 0.000
L1.Vorarlberg 0.107879 0.031794 3.393 0.001
L1.Wien 0.066616 0.057657 1.155 0.248
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061406 0.037740 1.627 0.104
L1.Burgenland 0.038870 0.025826 1.505 0.132
L1.Kärnten 0.049937 0.013875 3.599 0.000
L1.Niederösterreich 0.227061 0.054163 4.192 0.000
L1.Oberösterreich 0.267737 0.051258 5.223 0.000
L1.Salzburg 0.060025 0.027421 2.189 0.029
L1.Steiermark -0.006537 0.036021 -0.181 0.856
L1.Tirol 0.157472 0.029312 5.372 0.000
L1.Vorarlberg 0.069091 0.025214 2.740 0.006
L1.Wien 0.075650 0.045724 1.654 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185965 0.045257 4.109 0.000
L1.Burgenland 0.017912 0.030970 0.578 0.563
L1.Kärnten -0.060130 0.016639 -3.614 0.000
L1.Niederösterreich -0.095503 0.064951 -1.470 0.141
L1.Oberösterreich 0.175044 0.061467 2.848 0.004
L1.Salzburg 0.061643 0.032883 1.875 0.061
L1.Steiermark 0.230147 0.043195 5.328 0.000
L1.Tirol 0.488144 0.035149 13.888 0.000
L1.Vorarlberg 0.051384 0.030235 1.699 0.089
L1.Wien -0.052879 0.054830 -0.964 0.335
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158848 0.051342 3.094 0.002
L1.Burgenland -0.000300 0.035135 -0.009 0.993
L1.Kärnten 0.066454 0.018876 3.521 0.000
L1.Niederösterreich 0.200600 0.073684 2.722 0.006
L1.Oberösterreich -0.069614 0.069732 -0.998 0.318
L1.Salzburg 0.221371 0.037304 5.934 0.000
L1.Steiermark 0.112056 0.049003 2.287 0.022
L1.Tirol 0.085215 0.039876 2.137 0.033
L1.Vorarlberg 0.123519 0.034301 3.601 0.000
L1.Wien 0.103476 0.062203 1.664 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360020 0.030394 11.845 0.000
L1.Burgenland 0.007409 0.020799 0.356 0.722
L1.Kärnten -0.025621 0.011174 -2.293 0.022
L1.Niederösterreich 0.229031 0.043620 5.251 0.000
L1.Oberösterreich 0.152844 0.041281 3.703 0.000
L1.Salzburg 0.052716 0.022084 2.387 0.017
L1.Steiermark -0.016243 0.029010 -0.560 0.576
L1.Tirol 0.122275 0.023606 5.180 0.000
L1.Vorarlberg 0.071038 0.020306 3.498 0.000
L1.Wien 0.048214 0.036824 1.309 0.190
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038533 0.161535 0.181372 0.169095 0.143567 0.128077 0.066271 0.219018
Kärnten 0.038533 1.000000 0.001482 0.132200 0.026953 0.099207 0.432153 -0.049467 0.100921
Niederösterreich 0.161535 0.001482 1.000000 0.346540 0.170389 0.314674 0.128533 0.192674 0.339366
Oberösterreich 0.181372 0.132200 0.346540 1.000000 0.233888 0.342002 0.178094 0.179730 0.271791
Salzburg 0.169095 0.026953 0.170389 0.233888 1.000000 0.153629 0.136942 0.153292 0.139777
Steiermark 0.143567 0.099207 0.314674 0.342002 0.153629 1.000000 0.159888 0.148961 0.094761
Tirol 0.128077 0.432153 0.128533 0.178094 0.136942 0.159888 1.000000 0.123295 0.162333
Vorarlberg 0.066271 -0.049467 0.192674 0.179730 0.153292 0.148961 0.123295 1.000000 0.018660
Wien 0.219018 0.100921 0.339366 0.271791 0.139777 0.094761 0.162333 0.018660 1.000000